package com.jsbb.core;

import com.jsbb.core.enums.HttpCodeEnum;
import io.swagger.v3.oas.annotations.media.Schema;

/**
 * 接口响应
 *
 * @author jsbb
 */
public class Message<T> {

    @Schema(title = "响应码")
    private String code;

    @Schema(title = "响应码描述")
    private String message;

    @Schema(title = "响应数据")
    private T data;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Message() {
    }

    public Message(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 成功
     *
     * @return Message
     */
    public static Message success() {
        return success(null);
    }

    /**
     * 成功
     *
     * @param data data
     * @param <T>  T
     * @return Message
     */
    public static <T> Message success(T data) {
        return new Message(HttpCodeEnum.SUCCESS.getIndex(), HttpCodeEnum.SUCCESS.getValue(), data);
    }

    /**
     * 失败
     *
     * @param message message
     * @return Message
     */
    public static Message error(String message) {
        return new Message(HttpCodeEnum.ERROR.getIndex(), message, null);
    }

    /**
     * @param httpCodeEnum httpCodeEnum
     * @return Message
     */
    public static Message message(HttpCodeEnum httpCodeEnum) {
        return new Message(httpCodeEnum.getIndex(), httpCodeEnum.getValue(), null);
    }
}
